package com.study.common.util;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * string与unicode之间相互转换
 * @author hw
 * @date 2022/10/24 10:56:30
 */
public class UniCodeUtil {

    public static void main(String[] args) {
//        String str = "中国";
//        System.out.println(UniCodeUtil.StringToWebUnicode(str));
//        System.out.println(UniCodeUtil.WebUnicodeToString("&#20013;&#22269;"));
//        System.out.println(UniCodeUtil.StringToUnicode(str));
//        System.out.println(UniCodeUtil.UnicodeToString("\u4e2d\u56fd\\uqqqq"));
//        System.out.println(UniCodeUtil.WebUnicodeToString("&#25209;&#37327;&#23457;&#26680;&#20986;&#29616;&#24322;&#24120;"));
        System.out.println(UniCodeUtil.WebUnicodeToString("&#25104;&#21592;&#24555;&#29031;&#20449;&#24687;&#25209;&#37327;&#20445;&#23384;&#24322;&#24120;:&#25104;&#21592;&#40644;&#38892;&#25968;&#25454;&#24322;&#24120;&#65292;&#26657;&#39564;&#21442;&#25968;&#32570;&#22833;&#65281;"));
//        String a = "111"+null;
//        System.out.println(a);
//        System.out.println("{\"result\":[{\"hh\":\"001592690\",\"hkszd\":\"牛田镇水南村村头\",\"dqm\":\"江西省抚州市\",\"xz\":\"牛田镇水南村村头水南村头\",\"xm\":\"丁乃进\",\"hlx\":\"集体户\",\"gmsfhm\":\"362526195601222010\",\"zt_dic\":\"注销\",\"hjdz_cxfldm_dic\":\"镇乡结合区(城镇)\",\"zt\":3,\"BDRQ\":\"1525881600\",\"ssssxq\":\"江西省乐安县\"}],\"success\":true}");
        /*boolean isResult = true;
        do{
            System.out.println(DateUtil.now());
        }while (isResult);*/

        /*String result = "11111111";
        System.out.println(StrUtil.removeSuffix("张三、李四、王五、","、"));


        String password="11111111a!";
        if(ReUtil.isMatch("^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[^\\da-zA-Z\\s]).{8,16}$", password)){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }*/
        String url = "http://10.56.0.165:30005/verification-be/sdLogin/loginByEncryption?encryption=22880cd7e72adcbdbabb591c2c6850b8&id=84906566782c48219s5s5e8d030f58e9";
        HttpResponse response = HttpUtil.createGet(url).execute();
        List<String>  cookies = response.headerList("Set-Cookie");
        String cookie = "";
        for(String e : cookies){
            cookie = cookie.concat(e).concat(";");
        }
        System.out.println(cookie);


    }


    /**
     * 普通类型的unicode转string
     * @author hw
     * @date 2022/10/24 10:56:36
     * @param input:
     * @return java.lang.String
     */
    public static String UnicodeToString(String input) {
        Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
        Matcher matcher = pattern.matcher(input);
        char ch;
        while (matcher.find()) {
            ch = (char) Integer.parseInt(matcher.group(2), 16);
            input = input.replace(matcher.group(1), ch + "");
        }
        return input;
    }

    /**
     * string转普通类型的unicode
     * @author hw
     * @date 2022/10/24 10:57:03
     * @param input:
     * @return java.lang.String
     */
    public static String StringToUnicode(String input) {
        String str = "";
        for (char c : input.toCharArray()) {
            if ((int) c > 128)
                str += "\\u" + Integer.toHexString((int) c);
            else
                str += c;
        }
        return str;

    }

    /**
     * string转web类型的unicode
     * @author hw
     * @date 2022/10/24 10:57:12
     * @param input:
     * @return java.lang.String
     */
    public static String StringToWebUnicode(String input) {
        String str = "";
        for (char c : input.toCharArray()) {
            str += "&#" + (int) c + ";";
        }
        return str;
    }

    /**
     * web类型的unicode转string
     * @author hw
     * @date 2022/10/24 10:57:21
     * @param input:
     * @return java.lang.String
     */
    public static String WebUnicodeToString(String input) {
        String str = "";
        String[] y1 = input.split(";");
        for (String c : y1) {
            if (c.length() > 2) {
                String REGEX = "[^0-9]";
                String ticket = Pattern.compile(REGEX).matcher(c).replaceAll("").trim();
                System.out.println(ticket);
                str += (char) Integer.parseInt(ticket);
            }
        }
        return str;
    }
}